var getPathFloor = []; //存起点和终点的数组 
var saveFloor = []; // 存后台请求出来的所有楼层 
var saveCompareGet = []; // 存有路线的楼层 
var getToggleFloor = []; // 存切换模块的楼层 
var fFloor; //起点路径楼层号    1F
var mFloor; //中间路径楼层号
var lFloor; //终点路径楼层号
var fIndex; //起点路径楼层index
var mIndex; //中间路径楼层index
var lIndex; //终点路径楼层index
var fFloorid; //起点路径楼层id   模拟导航开头调用一次 self.map.showFloors(fFloorid)
var isInit = true; //是否是初始化
var mFloorid; //中间路径楼层id
var lFloorid; //终点路径楼层id
var msgLength; //msg的字段长度
var msgLong;
var nowPositionFloorNo;
var allData = [];
var dataO;
var textO;
var isPathGo = false;
var nowFloorId; //模拟导航内调用 拿到后台请求的当前所在的楼层   模拟导航方法内的regNavigationWalk方法内 调用一次nowFloorId = walkDetail.floorID;   取消模拟导航方法开头 调用一次$('.floorToggle').html("" + object.allFoors[nowFloorId] + "");
var arrT = []; //导航状态下  左侧按钮的楼层遍历出来楼层号
var isFloorToggleCounter = false; //楼层切换计数器开关，暂时用于处理当同层不同区导航时暂停后跳转的bug的属性   onSelected方法内的regNavigationPause方法内 调用一次isFloorToggleCounter = true; 继续模拟导航方法尾部 调用一次isFloorToggleCounter = false;
var floorCounter = 0; //楼层切换计数器   继续模拟导航方法尾部 调用一次floorCounter = 0;
// var isStartOrEnd = '';
var nowFloorToggleNo = '';
var object = {
  startPP: '', //设置起点时获取的起点楼层号   setStart方法内 调用一次object.startPP = object.allFoors[data.floorID] goBack方法开头和startP做相同格式判断
  endPP: '', //设置终点时获取的终点楼层号     setEnd方法内 调用一次object.endPP = object.allFoors[data.floorID] goBack方法开头和endP做相同格式判断
}
// 切换楼层模块主按钮点击事件
$(function () {
  $(".floorToggleContent3 .floorToggle").hide();
  $(".floorToggleContent3 .floorToggleUl").show();
  $(".swiper-pagination").hide()
  $(".floorToggleBox div").on("click", function () {
     $(this).find(".floorToggle").slideUp();
    $(this).find(".floorToggleUl").slideDown();
    $(this).siblings().find(".floorToggle").slideDown();
    $(this).siblings().find(".floorToggleUl").slideUp();
    if (isInit == true) {
      /* 控制滚动条 */
      var scrollHeight = $('.floorToggleUl').prop("scrollHeight");
      $('.floorToggleUl').scrollTop(scrollHeight, 200);
      // console.log("asd")
      isInit = false;
    }

  })


})
// 切换楼层模块 取外层div值判断内层div该显示哪层楼   在初始化initCompelte、点击地图onSelected、导航结束moEndClose moEndSend、返回goback、搜索后调用searchSetStart searchSetEnd
function FloorDetection() {
  var btnL = $(".floorToggleUl li button")
  for (let i = 0; i < btnL.length; i++) {
    // console.log(i)
    // if (btnL.length < 42) {
    //   $(".floorToggleUl").css("height", "auto")
    //   $(".floorToggleUl .floorToggleUlTop_i").hide()
    //   $(".floorToggleUl .floorToggleUlBottom_i").hide()
    // }
    if (nowFloorToggleNo == btnL.eq(i).html()) {
      // console.log(i)
      btnL.eq(i).parent().removeClass().addClass('floorToggleUl_List-active');
      btnL.eq(i).parent().siblings().removeClass().addClass('floorToggleUl_List')
      btnL.eq(i).parent().parent().parent().siblings().find(".floorToggleUl").children().removeClass().addClass('floorToggleUl_List')
      btnL.eq(i).find(".floorToggle").hide();
      btnL.eq(i).find(".floorToggleUl").show();
      btnL.eq(i).parent().parent().parent().find(".floorToggle").hide();
      btnL.eq(i).parent().parent().parent().find(".floorToggleUl").show();
      btnL.eq(i).parent().parent().parent().siblings().find(".floorToggle").show();
      btnL.eq(i).parent().parent().parent().siblings().find(".floorToggleUl").hide();
    }
	if ("25F" == btnL.eq(i).html()) {
      // console.log(nowPositionFloorNo)
      btnL.eq(i).css("color", "#006cb6")
      btnL.eq(i).parent().siblings().find("button").css("color", "#bebebe");
      btnL.eq(i).parent().parent().siblings().children().find("button").css("color", "#bebebe");
      btnL.eq(i).parent().parent().prev().css("color", "#006cb6")
      btnL.eq(i).parent().parent().parent().siblings().children("div:first-child").css("color", "#777777")
	  btnL.eq(i).parent().removeClass().addClass('floorToggleUl_List-active');
    }
  }

}
// 根据后台返回的数据  获取当前的楼层
function floorJudgment() {
  $("#floorToggleUl_List button").on("click", function () {
    arrT.push($(this).html().toString())
  })
  $(".floorToggleMinUl #floorToggleUl_List button").click()
  // console.log(arrT)
}
// 切换楼层模块列表按钮点击事件
$(function () {
	
	
  $("#floorToggleUl_List button").on("click", function () {
   
    textO = $(this).attr('value')
//  dataO = $(this).attr('data')
    nowFloorToggleNo = $(this).attr("id")
	
	if(Number(nowFloorToggleNo.slice(0,2))!==25) {
		$('.lc_tishi').show().fadeOut(3000)
		return 
	
	
	
    $(this).parent().removeClass().addClass('floorToggleUl_List-active');
    $(this).parent().siblings().removeClass().addClass('floorToggleUl_List')
    $(this).parent().parent().parent().siblings().find(".floorToggleUl").children().removeClass().addClass('floorToggleUl_List')
	self.map.zoomLevel(20)
    self.map.showFloors([dataO])
		self.map.setPolarAngle(0);
	self.map.setAzimuthalAngle(95);
	self.map.move2Point({
		x: 200,
		y: -400
	});
    $(".setPoint").hide()
    object.floorid = [dataO]
    if (isFloorToggleCounter == true && fFloor == lFloor) {
      floorCounter = floorCounter + 1
    }
	FloorDetection()
	}
  })
  
  
  $(".floorToggleMinUl").on("click", "button", function () {
    textO = $(this).attr('value')
//  dataO = $(this).attr('data')
   // console.log(nowFloorToggleNo)
   if(Number(nowFloorToggleNo.slice(0,2))!==25) {
		$('.lc_tishi').show().fadeOut(2000)
		return 
	
    $(this).parent().removeClass().addClass('floorToggleUl_List-active');
    $(this).parent().siblings().removeClass().addClass('floorToggleUl_List')
    $(this).parent().parent().parent().siblings().find(".floorToggleUl").children().removeClass().addClass('floorToggleUl_List')
    $(this).parent().find("i").removeClass().addClass('floorToggleMinUl_iR');
    $(this).parent().siblings().find("i").removeClass().addClass('floorToggleMinUl_i')
    self.map.showFloors([dataO])
    $(".setPoint").hide()
    object.floorid = [dataO]
    self.map.setPolarAngle(15);
    if (isFloorToggleCounter == true && fFloor == lFloor) {
      floorCounter = floorCounter + 1
    }
   }
  })
})

/* 获取楼层列表index */
function searchKeys(needle, haystack) {
  console.log("22")
  for (i in haystack) {
    if (haystack[i] == needle) {
      if (i.length = 1) {
        // fIndex = i
        return i
      }
    }
  }
}
// 出路线方法   在设置起点setStart 终点setEnd  起点终点交换reverse等地方调用
function pathGo() {
  $('.floorToggleMinUl').children().remove()
  if (object.startP !== "" && object.endP !== "") {
      if (object.startP == object.endP) {
        $(".searchPathFailMsg").html("起始点相同,请重新设置")
        $(".searchPathFailBox").fadeIn()
        return
      } else {
        isPathGo = true
        $(".scale,.floorToggleMinUl").css("bottom", "1.2rem")
        $('#loadings').css({
            'display': 'block'
          }).children('.load_xun').css({
            display: 'block'
          })
          .siblings().css({
            display: 'none'
          })
        $(".compass").css("top", "2.05rem");
        $(".goToPath").hide()
        self.map.searchPath(function (msg) {
          realdistance = Math.ceil(msg.dis / 50)
          $(".followMe").show()
          $(".followMe span span").html(realdistance)
          if (msg.type == 'done') {
            self.map.areaClickEmbed = false;
            getPathFloor = [];
            saveFloor = [];
            saveCompareGet = [];
            getToggleFloor = [];
            getPathFloor.push(object.startPP)
            getPathFloor.push(object.endPP)
            // console.log(getPathFloor)
            // console.log("起点终点" + getPathFloor)
            var btnL = $("#floorToggleUl_List button")
            for (let i = 0; i < btnL.length; i++) {
              saveFloor.push(btnL.eq(i).val())
              // console.log(saveFloor.length)
              if (saveFloor.length > 42) {
                // console.log("后台总楼层" + saveFloor)
                $(".floorToggleMinUl").show();
                saveCompareGet = saveFloor.filter(function (n) {
                  return getPathFloor.indexOf(n) != -1
                });
                // console.log(saveFloor)
                // console.log("有路线的楼层" + saveCompareGet);
                // console.log(saveCompareGet.toString())
                if (msg.floorIDs.length == 2) {
                  msgLong = 2
                  fFloorid = msg.floorIDs.slice(0, 1)
                  lFloorid = msg.floorIDs.slice(1, 2)
                  fFloor = object.flooridFloors[msg.floorIDs.slice(0, 1).toString()]
                  lFloor = object.flooridFloors[msg.floorIDs.slice(1, 2).toString()]
                  var fFloorLi = `<li class="floorToggleUl_List-active" id="floorToggleUl_List"><i class="floorToggleMinUl_i"></i><button name="btn" data="${fFloorid}" value="${fFloor}" id="${fFloor}">${fFloor}</button></li>`
                  var lFloorLi = `<li class="floorToggleUl_List-active" id="floorToggleUl_List"><i class="floorToggleMinUl_i"></i><button name="btn" data="${lFloorid}" value="${lFloor}" id="${lFloor}">${lFloor}</button></li>`
                  $(".floorToggleMinUl").append(lFloorLi);
                  $(".floorToggleMinUl").append(fFloorLi);
                  // console.log(fIndex, lIndex)
                  // console.log(lIndex)
                  $(".floorToggleMinUl li").eq(1).show().removeClass().addClass('floorToggleUl_List-active')
                  $(".floorToggleMinUl li").eq(1).siblings().show().removeClass().addClass('floorToggleUl_List')
                  $(".floorToggleMinUl li").eq(-1).find('i').show().removeClass().addClass("floorToggleMinUl_iR")
                } else if (msg.floorIDs.length == 3) {
                  msgLong = 3
                  fFloorid = msg.floorIDs.slice(0, 1)
                  mFloorid = msg.floorIDs.slice(1, 2)
                  lFloorid = msg.floorIDs.slice(2, 3)
                  fFloor = object.allFoors[msg.floorIDs.slice(0, 1).toString()]
                  mFloor = object.allFoors[msg.floorIDs.slice(1, 2).toString()]
                  lFloor = object.allFoors[msg.floorIDs.slice(2, 3).toString()]
                  // console.log(fIndex)
                  // console.log(mFloor)
                  // console.log(lFloor)
                  var fFloorLi = `<li class="floorToggleUl_List-active" id="floorToggleUl_List"><i class="floorToggleMinUl_i"></i><button name="btn" data="${fFloorid}" value="${fFloor}" id="${fFloor}">${fFloor}</button></li>`
                  var mFloorLi = `<li class="floorToggleUl_List-active" id="floorToggleUl_List"><i class="floorToggleMinUl_i"></i><button name="btn" data="${mFloorid}" value="${mFloor}" id="${mFloor}">${mFloor}</button></li>`
                  var lFloorLi = `<li class="floorToggleUl_List-active" id="floorToggleUl_List"><i class="floorToggleMinUl_i"></i><button name="btn" data="${lFloorid}" value="${lFloor}" id="${lFloor}">${lFloor}</button></li>`
                  $(".floorToggleMinUl").append(lFloorLi);
                  $(".floorToggleMinUl").append(mFloorLi);
                  $(".floorToggleMinUl").append(fFloorLi);
                  $(".floorToggleMinUl li").eq(2).show().removeClass().addClass('floorToggleUl_List-active')
                  $(".floorToggleMinUl li").eq(2).siblings().show().removeClass().addClass('floorToggleUl_List')
                  $(".floorToggleMinUl li").eq(1).find('i').show()
                  $(".floorToggleMinUl li").eq(-1).find('i').show().removeClass().addClass("floorToggleMinUl_iR")
                } else if (msg.floorIDs.length == 1) {
                  msgLong = 1
                  fFloorid = lFloorid = msg.floorIDs.slice(0, 1)
                  fFloor = object.flooridFloors[msg.floorIDs.slice(0, 1).toString()]
                  // console.log(fFloor)
                  // console.log(saveFloor)
                  // console.log(fIndex)
                  var fFloorLi = `<li class="floorToggleUl_List-active" id="floorToggleUl_List"><i class="floorToggleMinUl_i"></i><button name="btn" data="${fFloorid}" value="${fFloor}" id="${fFloor}">${fFloor}</button></li>`
                  $(".floorToggleMinUl").append(fFloorLi);
                }
                $(".floorToggleBox").hide();
                if (object.startPP !== "" && object.endPP !== "") {}
              }
            }
            self.map.showFloors([msg.floorIDs.slice(0, 1).toString()])
            self.map.zoomLevel(15);
            object.isFind = true;
            self.map.setPolarAngle(0)

            $('#loadings,.looking').css('display', 'none')
          } else {
            $('#loadings').css('display', 'none')
            $(".searchPathFailBox").fadeIn()
            return;
          }
        })
      }
  }
}
//在onSelected内的导航状态下 移动地图暂停导航内贴上以下代码块 [██████code block██████]
// isFloorToggleCounter = true;
// $(".floorToggleMinUl li button").removeAttr("disabled");


// 在继续导航内的 isPause == truen内调用
function goOnInside() {
  self.map.showFloors([nowFloorId])
  var ffFloorNo = object.allFoors[nowFloorId]
  // console.log(ffFloorNo)
  // console.log(fFloor)
  if (fFloor == lFloor && floorCounter > 0) {
    // console.log("1")
    if (ffFloorNo == fFloor && ffFloorNo == lFloor) {
      // console.log("2")
      $(".floorToggleMinUl li").eq(2).show().removeClass().addClass('floorToggleUl_List-active')
      $(".floorToggleMinUl li").eq(2).siblings().show().removeClass().addClass('floorToggleUl_List')
      $(".floorToggleMinUl li").eq(2).find('i').removeClass().addClass("floorToggleMinUl_iR")
      $(".floorToggleMinUl li").eq(2).siblings().find('i').removeClass().addClass("floorToggleMinUl_i")
    } else if (ffFloorNo !== fFloor && ffFloorNo !== lFloor && ffFloorNo == mFloor) {
      var ffIndex = searchKeys(ffFloorNo, arrT)
      $(".floorToggleMinUl li").eq(ffIndex).show().removeClass().addClass('floorToggleUl_List-active')
      $(".floorToggleMinUl li").eq(ffIndex).siblings().show().removeClass().addClass('floorToggleUl_List')
      $(".floorToggleMinUl li").eq(ffIndex).find('i').removeClass().addClass("floorToggleMinUl_iR")
      $(".floorToggleMinUl li").eq(ffIndex).siblings().find('i').removeClass().addClass("floorToggleMinUl_i")
    }
  } else if (fFloor !== lFloor) {
    var ffIndex = searchKeys(ffFloorNo, arrT)
    // console.log("4")
    $(".floorToggleMinUl li").eq(ffIndex).show().removeClass().addClass('floorToggleUl_List-active')
    $(".floorToggleMinUl li").eq(ffIndex).siblings().show().removeClass().addClass('floorToggleUl_List')
    $(".floorToggleMinUl li").eq(ffIndex).find('i').removeClass().addClass("floorToggleMinUl_iR")
    $(".floorToggleMinUl li").eq(ffIndex).siblings().find('i').removeClass().addClass("floorToggleMinUl_i")
  }
}

// 在继续导航方法结尾贴上以下代码块 [██████code block██████]
// isFloorToggleCounter = false;
// floorCounter = 0;
// $(".floorToggleMinUl li button").attr("disabled", "true")

// 在模拟导航结束方法和取消方法调用
function moEndClear() {
  object.startP = '';
  object.endP = '';
  object.startPP = '';
  object.endPP = '';
  object.isFind = false

  $(".floorToggle").show()
  $('.floorToggleUl').hide()
  $(".floorToggleUl li").show()
  $(".floorToggleMinUl li button").removeAttr("disabled");
  $('.floorToggleMinUl').children().remove()
}

// 在返回方法goback内调用
function goBackInside(params) {
  $(".floorToggleMinUl li button").removeAttr("disabled");
  $('.floorToggleMinUl').children().remove()
  $(".floorToggleMinUl li").eq(fIndex).find('i').hide()
  $(".floorToggleMinUl li").eq(mIndex).find('i').hide()
  $(".floorToggleMinUl li").eq(lIndex).find('i').hide()
  self.map.addMarkToPoint(nowPositionpoint, 'start')
	object.startP = self.map.startNode.pointID = nowPositionpoint;
  fFloor = "";
  mFloor = "";
  lFloor = "";
  fFloorid = ""
  mFloorid = ""
  lFloorid = ""
  fIndex = "";
  mIndex = "";
  lIndex = "";
  object.endP = '';
  object.startPP = '';
  object.endPP = '';
  isPathGo  =false;
  $(".floorToggleMinUl").hide()
  $(".followMe").hide()
  $(".floorToggleBox").show()
  $(".scale,.floorToggleBox").css("bottom", ".4rem")
}

// 起点终点置换方法内调用
function reverseInside() {
  $('.floorToggleMinUl').children().remove()
  if (msgLong > 1) {
    var bbc
    bbc = fIndex;
    fIndex = lIndex;
    lIndex = bbc;
  }
  $(".floorToggleMinUl li").css("display", "block")
}

// 在模拟导航方法if判断中贴上以下代码块 [██████code block██████]
// else if (walkDetail.turn == 'Lifts' && walkDetail.dis == 0) {
//   $(".floorToggleUl_List-active").prev().removeClass().addClass("floorToggleUl_List-active").siblings().removeClass().addClass("floorToggleUl_List")
//   $(".floorToggleUl_List-active").find("i").removeClass().addClass("floorToggleMinUl_iR").parent().siblings().find("i").removeClass().addClass("floorToggleMinUl_i")
// }
function GoTopathing() {
  $(".operation").show();
  $(".goToPath,.nav_qyfg,.bg_gSearch").hide();
  $(".compass").css("top", "2.05rem")
  $("#endPoint").focus()
}
